home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / misc / iv26_w30 / intervie / transfor.h < prev    next >
C/C++ Source or Header  |  1980-01-03  |  4KB  |  110 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Interface to transformation matrices.
  25.  */
  26.  
  27. #ifndef transformer_h
  28. #define transformer_h
  29.  
  30. #include <InterViews/defs.h>
  31. #include <InterViews/resource.h>
  32.  
  33. class Transformer : public Resource {
  34. public:
  35.     Transformer(Transformer* t =nil);        // returns identity if t == nil
  36.     Transformer(
  37.     float a00, float a01, float a10, float a11, float a20, float a21
  38.     );
  39.  
  40.     void GetEntries(
  41.     float& a00, float& a01, float& a10, float& a11, float& a20, float& a21
  42.     );
  43.     void Premultiply(Transformer* t);
  44.     void Postmultiply(Transformer* t);
  45.     void Invert();
  46.  
  47.     void Translate(float dx, float dy);
  48.     void Scale(float sx, float sy);
  49.     void Rotate(float angle);
  50.     boolean Translated (float = 1e-6);
  51.     boolean Scaled (float = 1e-6);
  52.     boolean Stretched (float = 1e-6);
  53.     boolean Rotated (float = 1e-6);
  54.     boolean Rotated90 (float = 1e-6);
  55.  
  56.     void Transform(Coord& x, Coord& y);
  57.     void Transform(Coord x, Coord y, Coord& tx, Coord& ty);
  58.     void Transform(float x, float y, float& tx, float& ty);
  59.     void TransformList(Coord x[], Coord y[], int n);
  60.     void TransformList(Coord x[], Coord y[], int n, Coord tx[], Coord ty[]);
  61.     void TransformRect(Coord&, Coord&, Coord&, Coord&);
  62.     void TransformRect(float&, float&, float&, float&);
  63.     void InvTransform(Coord& tx, Coord& ty);
  64.     void InvTransform(Coord tx, Coord ty, Coord& x, Coord& y);
  65.     void InvTransform(float tx, float ty, float& x, float& y);
  66.     void InvTransformList(Coord tx[], Coord ty[], int n);
  67.     void InvTransformList(Coord tx[], Coord ty[], int n, Coord x[], Coord y[]);
  68.     void InvTransformRect(Coord&, Coord&, Coord&, Coord&);
  69.     void InvTransformRect(float&, float&, float&, float&);
  70.  
  71.     boolean operator == (Transformer&);
  72.     boolean operator != (Transformer&);
  73.     Transformer& operator = (Transformer&);
  74. private:
  75.     float Det(Transformer*);
  76. private:
  77.     float mat00, mat01, mat10, mat11, mat20, mat21;
  78. };
  79.  
  80. inline float Transformer::Det (Transformer *t) {
  81.     return t->mat00*t->mat11 - t->mat01*t->mat10;
  82. }
  83.  
  84. inline boolean Transformer::Translated (float tol) {
  85.     return -tol > mat20 || mat20 > tol || -tol > mat21 || mat21 > tol;
  86. }
  87.  
  88. inline boolean Transformer::Scaled (float tol) {
  89.     float l = 1 - tol, u = 1 + tol;
  90.  
  91.     return l > mat00 || mat00 > u || l > mat11 || mat11 > u;
  92. }
  93.  
  94. inline boolean Transformer::Stretched (float tol) {
  95.     float diff = mat00 - mat11;
  96.  
  97.     return -tol > diff || diff > tol;
  98. }
  99.  
  100. inline boolean Transformer::Rotated (float tol) {
  101.     return -tol > mat01 || mat01 > tol || -tol > mat10 || mat10 > tol;
  102. }
  103.  
  104. inline boolean Transformer::Rotated90 (float tol) {
  105.     return Rotated(tol) && -tol <= mat00 && mat00 <= tol && 
  106.         -tol <= mat11 && mat11 <= tol;
  107. }
  108.  
  109. #endif
  110.